package net.keebook.webapp.dao;

import java.sql.Timestamp;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import net.keebook.webapp.entity.AccountConfirmation;


@Stateless
public class AccountConfirmationDao extends Dao<AccountConfirmation> {
	@Override
	public void store(AccountConfirmation item) {
		super.store(item);
	}
	
	@Override
	public void update(AccountConfirmation item) {
		super.update(item);
	}
	
	@Override
	public AccountConfirmation get(Long id) {
		return super.get(id);
	}
	
	@Override
	public AccountConfirmation get(String id) {
		return super.get(id);
	}
	
	@Override
	public void delete(AccountConfirmation item) {
		super.delete(item);
	}
	
	public void deleteAllUserConfirmations(Long userId) {
		getEntityManager().createQuery("DELETE FROM AccountConfirmation a WHERE a.user.id = :userId").setParameter("userId", userId).executeUpdate();
	}
	
	@SuppressWarnings("unchecked")
	public List<AccountConfirmation> getOlderThan(Timestamp timestamp) {
		Query query = getEntityManager().createQuery("from AccountConfirmation a where a.creationDate <= :compareDate and a.permanent = false");
		query.setParameter("compareDate", timestamp);
		return (List<AccountConfirmation>)query.getResultList();
	}
}
